Skip to content

fix #4278: proxy all methods in ProxiedProducer/Consumer#4358

Open
JMGalvao wants to merge 2 commits intoopen-telemetry:mainfrom
JMGalvao:fix/proxied-delegation-4278
Open

fix #4278: proxy all methods in ProxiedProducer/Consumer#4358
JMGalvao wants to merge 2 commits intoopen-telemetry:mainfrom
JMGalvao:fix/proxied-delegation-4278

Conversation

@JMGalvao
Copy link
Copy Markdown

Description

Fixes #4278

ProxiedProducer and ProxiedConsumer inherited from the confluent-kafka C-extension classes (Producer/Consumer) but never called super().__init__(). Any method not explicitly defined on the proxy class fell through to the base class with an uninitialized C handle, causing RuntimeError: Handle has been closed / Consumer closed.

The fix removes inheritance and uses pure composition with __getattr__ to delegate all undefined method calls to the wrapped instance.

Type of Change

  • Bug fix (non-breaking change which fixes an issue)

Testing

Added two regression tests:

  • test_proxied_producer_delegates_undefined_methods — calls list_topics() on ProxiedProducer and verifies it delegates to the underlying producer
  • test_proxied_consumer_delegates_undefined_methods — calls assignment() on ProxiedConsumer and verifies it delegates to the underlying consumer

Does This Require a Core Repo Change?

  • No

Checklist

  • Followed the style guidelines of this project
  • Changelogs updated for any user-facing changes
  • Unit tests added covering the changes

@JMGalvao JMGalvao requested a review from a team as a code owner March 25, 2026 21:59
@linux-foundation-easycla
Copy link
Copy Markdown

linux-foundation-easycla Bot commented Mar 25, 2026

CLA Signed

The committers listed above are authorized under a signed CLA.

  • ✅ login: JMGalvao / name: João Galvão (a4419bd)
  • ✅ login: tammy-baylis-swi / name: Tammy Baylis (5f515d0)

@tammy-baylis-swi
Copy link
Copy Markdown
Contributor

Thanks for this! Please pull as I did a changelog resolve before triggering workflows.

Please then could you address the lint issues with:

  • tox -e lint-instrumentation-confluent-kafka
  • tox -e precommit

Remove Producer/Consumer inheritance from
ProxiedProducer and ProxiedConsumer. Add
__getattr__ to delegate undefined methods
to the wrapped client, fixing segfaults on
calls like list_topics() or assignment().

Add regression tests to verify delegation
of undefined methods on both proxy classes.
@JMGalvao JMGalvao force-pushed the fix/proxied-delegation-4278 branch from 2baa7b6 to a4419bd Compare March 26, 2026 14:00
@tammy-baylis-swi tammy-baylis-swi moved this to Ready for review in Python PR digest Mar 26, 2026
@tammy-baylis-swi tammy-baylis-swi moved this from Ready for review to Easy to review / merge / close in Python PR digest Mar 26, 2026
Copy link
Copy Markdown
Contributor

@tammy-baylis-swi tammy-baylis-swi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks again! Maintainers will also have a look

@github-actions
Copy link
Copy Markdown

This PR has been automatically marked as stale because it has not had any activity for 14 days. It will be closed if no further activity occurs within 14 days of this comment.
If you're still working on this, please add a comment or push new commits.

@github-actions github-actions Bot added the Stale label Apr 10, 2026
@tammy-baylis-swi tammy-baylis-swi requested a review from a team April 13, 2026 23:29
@github-actions github-actions Bot removed the Stale label Apr 14, 2026
@MikeGoldsmith MikeGoldsmith moved this from Easy to review / merge / close to Approved PRs in Python PR digest Apr 15, 2026
return super().close()


class ProxiedProducer(Producer):
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't this going to break any isinstance() that may be used by downstream users? I think the right solution would be to use wrapt object proxies instead.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I missed this before. This is right, it would be a breaking change and any isinstance calls would now return False.

I agree using wrapt would be a better solution.

Copy link
Copy Markdown
Member

@MikeGoldsmith MikeGoldsmith left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As per @xrmx's comment, this would be a breaking change. We should consider using wrapt instead to keep the type hierarchy the same.

@github-project-automation github-project-automation Bot moved this from Approved PRs to Reviewed PRs that need fixes in Python PR digest Apr 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Reviewed PRs that need fixes

Development

Successfully merging this pull request may close these issues.

[ConfluentKafkaInstrumentor] Not all methods are supported by returned proxy objects

4 participants